package com.notes.designpattern.chain2.handler;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.notes.designpattern.chain2.BusinHandler;
import com.notes.designpattern.chain2.BusinHandlerChain;

import java.util.Map;

/**
 * @author
 * @Describe 功能描述
 * @date
 */
public class BusinTwoHandler implements BusinHandler {

    String businName;
    public BusinTwoHandler(String businName) {
        this.businName = businName;
    }

    @Override
    public Map<String, Object> process(Map<String, Object> req, BusinHandlerChain businHandlerChain) {
        System.out.println("开始执行" + this.businName + ": " + JSON.toJSONString(req));
        Map<String, Object> resMap = Maps.newHashMap();
        resMap.put("businKey2", "BusinTwoHandler");
        resMap.putAll(req);
        if (this.businName.equals("BusinTwoHandler")) {
            resMap.put("success", "true");
            System.out.println("开始执行" + this.businName + "成功，出参: " + JSON.toJSONString(resMap));
            return businHandlerChain.process(resMap, businHandlerChain);
        }
        resMap.put("success", "false");
        System.out.println("开始执行" + this.businName + "失败，出参: " + JSON.toJSONString(resMap));
        return resMap;
    }
}
